import React, {Component} from 'react'
import Comment from './Comment'
import Props from 'prop-types'
class CommentList extends Component {
  static propTypes = {
    comments: Props.array,
    onDeleteComment: Props.func
  }
  static defaultProps = {
    comments: [],
  }
  handleDeleteComment (index) {
    if (this.props.onDeleteComment) {
      this.props.onDeleteComment(index)
    }
  }

  render() {
    return (
      <div>
          {this.props.comments.map(
            (comment, i) =><Comment comment={comment} index={i} onDeleteComment={this.handleDeleteComment.bind(this)} key={i}/>
          )}
      </div>
    )
  }
}

export default CommentList